var removeDuplicates = function(s) {
    let n = s.length;
    let i = 1;
    let res = [s[0]];
    while(i < n) {
        if(s[i] == res[res.length - 1]) {
            res.pop()
        } else {
            res.push(s[i]);
        }
        i++;
    }
   return res.join('')
};
console.log(removeDuplicates('abbaca'))